/*
 	This file is part of ExportGnuCash.

    ExportGnuCash is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ExportGnuCash is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ExportGnuCash.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.sourceforge.gnucash.model;

import java.util.ArrayList;
import java.util.List;


public class Transaction
{
    /** The posting date in YYYY-MM-DD format */
    public String datePosted;
    
    /** The due date in YYYY-MM-DD format */
    public String dateDue;

    /** The description of the transaction */
    public String description;

    /** The reference number, if any */
    public String ref;

    /** The splits in this transaction (usually two) */
    public List<Split> splits = new ArrayList<Split>(2);
    
    /** The GUID of this transaction */
    public String guid;
    
    /** The transaction type */
    public String transactionType;
    
    /** Export transaction type (used by IIF; not from GnuCash) */
    public String exportTransactionType;

    /**
     * Returns a stringified version of this object
     * @return A stringified version of this object
     */
    public String toString() {
    	return "\"" + description + "\" on " + datePosted + ((ref == null)? "": " with ref \"" + ref + "\"");
    }

    public Split getSplit(String accountGuuid ) {
        for (Split s : splits) {
            if (s.accountGuid.equals(accountGuuid)) {
                return s;
            }
        }
        return null;
    }
    
    public Split getOtherSplit(String accountGuuid ) {
    	Split other = null;
        for (Split s : splits) {
            if (s.accountGuid.equals(accountGuuid)) {
                continue;
            }
            other = s;
            break;
        }
        return other;
    }
    
    public boolean isSplit() {
    	return splits.size() > 2;
    }
}
